<template>
    <div style="padding: 20px;">
        <div>
          <el-button
            @click="insertData"
            size="mini"
            type="primary"
            style="margin-bottom: 10px">
          <i class="el-icon-circle-plus-outline"></i> 插入数据</el-button>
          <el-button
            @click="commitList"
            size="mini"
            type="primary"
           >
        保存数据</el-button>
        <el-button
            @click="$router.go(-1)"
            size="mini"
        >
        返回</el-button>
        </div>
        <el-table  max-height="650px" :header-cell-style="getRowClass" border :data="lcListOptions" class="tableAutoBtn">
          <el-table-column
            label="序号"
            align="center"
            type="index"
            width="50">
          </el-table-column>
          <qttable ref="qttableeditRef"  v-for="(item,index) in tabUserList2" :key="index" :header="item"></qttable>
          <el-table-column align="center" width="80" prop="" label="操作">
                <template slot-scope="scope">
                  <el-popconfirm
                    title="确定删除吗？"
                    icon-color="#f00"
                    @confirm="deleteRowData(scope.row,scope.$index)"
                  >
                    <el-button slot="reference" size="mini" type="danger"
                      >删除</el-button
                    >
                  </el-popconfirm>
                </template>
              </el-table-column>
       </el-table>


       <el-dialog title="插入数据"
      :visible.sync="addTableDataFlag"
      :close-on-click-modal="false"
      width="50%"
      >
      <!-- @setTableValList="setTableValList"  -->
      <addtable ref="addtable" v-if="addTableDataFlag" :formItem="formItem"></addtable>
    </el-dialog>
    </div>
</template>

 
<script>
import addtable from './tableform';
import {getExternalParameterColum} from '@/api/home_/adminCenter';
import qttableedit from '../components/qt_header_table_noedit'
import request from '@/utils/request';
import qttable from '../components/qt_header_table';
import qttableno from '../components/qt_header_table_noedit';
export default {
  mixins: [ ],
  components: { qttable, qttableno,qttableedit,addtable },
  data() {
    return {
        formItem:ull,
        addTableDataFlag:false,
        lcListOptions:[],
        place:"",
        tabUserList2:[],
        deployId:"",
        addObj:{},
    };
  },
  created() {
    let paramsData = JSON.parse(this.$route.query.paramsObj)
    this.place = paramsData.place
    this.deployId = paramsData.deployId
    getExternalParameterColum(this.deployId).then(res=>{
      this.tabUserList2 = res.data.colum||[]
      this.lcListOptions = res.data.data
      this.setObjAttr(this.tabUserList2)
    })
  },
  methods: {
    insertData(){
      this.addTableDataFlag = true
      // let a = JSON.parse(JSON.stringify(this.lcListOptions))
      // a.push(this.addObj)
      // this.lcListOptions = JSON.parse(JSON.stringify(a))
    },
    commitList(){
        this.lcListOptions.forEach((item,index)=>{
          item.deployId =  this.deployId
        })
        request({
          url: '/ht-bpmn/basicData/addList',
          method: 'post',
          data:this.lcListOptions
        }).then((res) => {
          if (res.code == 200) {
            this.$message.success('保存成功')
           this.$router.go(-1)
          } else {}
        });
    },
    setObjAttr(v){
      v.forEach((item,index)=>{
        if(item.children&&item.children.length>0){
          this.setObjAttr(item.children)
        }else{
          this.addObj[item.jsonKey] = ""
        }
      })
    },
    deleteRowData(row,index){
      this.lcListOptions.splice(index,1)
    },

    getRowClass({ rowIndex, columnIndex }) {
        if (rowIndex == 0) {
            return 'background:#f2f5f8;'
        }
    },
  }
};
</script>
  
<style lang="scss" scoped>